package com.situ.util.controller;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
@Component
public class LostTimer {

    @PostConstruct
    public void ContextInitializer(){
        // 写一个上下文监听器  servletContextListener
        //	 , 在初始化方法里面写
        Timer t=new Timer();
        t.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                try {

                    System.out.println("开始查询数据库 判断不是星期2 2点");
                    Calendar c=Calendar.getInstance(); //日历类
                    //这行不写 就是当前时间
                    int year = c.get(Calendar.YEAR);
                    int month = c.get(Calendar.MONTH);
                    int date = c.get(Calendar.DATE);

                    int minute = c.get(Calendar.MINUTE);
                    int second = c.get(Calendar.SECOND);

                    int hour = c.get(Calendar.HOUR_OF_DAY);
                    int weekday=c.get(c.DAY_OF_WEEK)-1;
                    System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
                     //获得是星期几  星期天是0  1 2
                    if(weekday==1){
                        System.out.println(c.get(c.DAY_OF_WEEK)-1+"--------");
                        //获得是几点,判断..是不是礼拜6 是不是2点如果是就 查数据库  ...
                        if(hour==11){
                            //查超过6个月都没有都无记录的用户

                            //如果流失表没这个客户的记录，就添加，如果有，就不添加
                            System.out.println(c.get(c.HOUR_OF_DAY)+"---------");

                        }
                    }





                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, 0, 3600*1000); //每小时判断一次

    }



}
